﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;

namespace MvcRags.Filtering
{
    public static class SelectHelper
    {
        public static List<SelectListItem> GetSelectListItemsFromProperties(Type t, string defaultPropertyName="")
        {
            List<SelectListItem> items = new List<SelectListItem>();
            PropertyInfo[] props = t.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                if (prop.PropertyType == typeof(string))
                    items.Add(new SelectListItem() { 
                        Text = prop.Name, 
                        Value = prop.Name.ToLower(), 
                        Selected = prop.Name == defaultPropertyName 
                    });
            }
            return items;
        }
    }
}